package com.iweb.day06.factory;

import java.util.Scanner;

/**
 * @author jay
 * @date 2021/10/31
 * @desc
 */
public class TestCalc {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 计算器对象
        Operation operation = null;
        System.out.print("请输入运算符(+-*):");
        String operator = scanner.next();
        int result = 0;
        // 判断运算符, 根据不同的运算需求, 实例化对应的子类对象,来提供服务
        operation = SimpleFactory.createOperation(operator);

        if (operation == null) {
            // 对应的子类对类不存在
            System.out.println("暂时不支持该运算。。。");
            // 直接从该位置终止当前方法
            return;
        }

        System.out.print("请输入第一个数字:");
        operation.numA = scanner.nextInt();

        System.out.print("请输入第二个数字:");
        operation.numB = scanner.nextInt();

        // 执行运算
        result = operation.getResult();
        System.out.println("result:" + result);
    }
}
